/*
 * Copyright (c) 2020, 2025, keyila All rights reserved.
 *
 */
package EasyExcel.test;

import EasyExcel.entity.ZhuZi;
import EasyExcel.listener.ZhuZiListener;
import com.alibaba.excel.EasyExcel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author clp
 * @version 1.0
 */
public class SimpleDemo {
    public static void writeDemo() {
        List<ZhuZi> zhuZis = new ArrayList<ZhuZi>();
        ZhuZi zhuZi = new ZhuZi(1L, "竹子", "男", "熊猫", new Date());
        zhuZis.add(zhuZi);

        // 可以写绝对路径，没有绝对路径默认放在当前目录下
        String folderPath = "E:\\clp_beijing\\clp_beijing\\clp_other_study\\src\\main\\resources\\Excel";
        String fileName = "竹子数据-" + System.currentTimeMillis() + ".xlsx";
        String fullName = folderPath + "\\" + fileName;
        EasyExcel.write(fullName, ZhuZi.class).sheet("竹子数据").doWrite(zhuZis);
    }

    public static void main(String[] args) {
        writeDemo();
//        readDemo();
    }

    public static void readDemo() {
        String folderPath = "E:\\clp_beijing\\clp_beijing\\clp_other_study\\src\\main\\resources\\Excel";
        String fileName = "竹子数据-1753673250926.xlsx";
        String fullName = folderPath + "\\" + fileName;
        ZhuZiListener zhuZiListener = new ZhuZiListener();
        // 读取指定路径的文件，并转换为ZhuZi对象，默认会读取第一个sheet单元
        EasyExcel.read(fullName, ZhuZi.class, zhuZiListener).sheet().doRead();
        List<ZhuZi> zhuZis = zhuZiListener.getData();
        System.out.println("读取excel文件结束，总计解析到" + zhuZis.size() + "条数据！");
    }


}
